package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.starter.cache.aspect.annotation.MallCache;
import com.atguigu.gmall.weball.vo.CategoryTreeVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;


// 远程调用时返回JSON
@Api("分类的rpc")
@RequestMapping("/api/inner/rpc/product")
@RestController
public class CategoryRpcController {
    @Autowired
    BaseCategory1Service baseCategory1Service;

    // 【查询所有分类】得到分类的树形结构数据
    @MallCache(cacheKey = RedisConst.CACHE_CATEGORYS)
    @GetMapping("/category/tree")
    public Result<List<CategoryTreeVo>> getCategoryTreeData() {
        List<CategoryTreeVo> categoryList = baseCategory1Service.getCategoryTreeData();
        return Result.ok(categoryList);
    }

    //三级分类id得到完整路径
    @GetMapping("/category/view/{c3Id}")
    public Result<CategoryTreeVo> getCategoryTreeVoByC3Id(@PathVariable("c3Id") Long c3Id) {
        CategoryTreeVo categoryTreeVo = baseCategory1Service.getCategoryTreeVoByC3Id(c3Id);
        return Result.ok(categoryTreeVo);
    }
}
